import cv2 as cv

# 读取图像
image = cv.imread("c5a134aaly1hmqiuhn0imj22p83lm7wo.jpg")

b, g, r = cv.split(image)  # 拆分图像通道为b、g、r三个通道

# 显示各个通道的图像信息
cv.imshow("Blue Channel", b)
cv.imshow("Green Channel", g)
cv.imshow("Red Channel", r)
cv.imshow("Original Image", image)

# 将绿色和红色通道置零
cur_img = image.copy()
cur_img[:, :, 1] = 0  # 将绿色通道置零
cur_img[:, :, 2] = 0  # 将红色通道置零
cv.imshow("Image with Red and Green Channels Removed", cur_img)

# 创建一个与原始图像相同大小的全零图像
zero_shape = image.copy()
zero_shape[:, :] = 0

# 合并蓝色通道和全零矩阵，保留蓝色通道，其他通道为零
cur_img = cv.merge([b, zero_shape, zero_shape])
cv.imshow("Image with Only Blue Channel", cur_img)

cv.waitKey(0)
cv.destroyAllWindows()
